Attribute VB_Name = "ModDB"
Option Explicit

'crea un nuovo mdb2000 nel percorso path (percorso + nome)
Public Function CreateDatabase(ByVal path As String) As Boolean
    On Error GoTo ErrorCreateDB

    Dim Cat     As New ADOX.Catalog
    Dim Tbl(12) As ADOX.Table
    Dim Idx()   As ADOX.Index
    Dim cmb     As ADODB.Command
    Dim rst     As ADODB.Recordset
    Dim cnn     As ADODB.Connection
    Dim kyForeign As ADOX.Key
    Dim msgErrR As Integer
    Dim sCnn    As String
    Dim i       As Long

    sCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Engine Type=5;Data Source=" & path
    Cat.Create sCnn
    
    '----------* Table Definition of TblData *----------
    Set Tbl(7) = New ADOX.Table
    Tbl(7).ParentCatalog = Cat
    With Tbl(7)
        .Name = "TblData"
        .Columns.Append "DataUltimoInserimento", adDate
            .Columns("DataUltimoInserimento").Properties("Nullable").value = True
            '.Columns("DataUltimoInserimento").Attributes = adColFixed '.Properties(adPropRequired).value = IS_REQ
            .Columns("DataUltimoInserimento").Properties("Jet OLEDB:Compressed UNICODE Strings").value = False
            .Columns("DataUltimoInserimento").Properties("Default").value = vbNullString
    End With
    Cat.Tables.Append Tbl(7)
    
    '----------* Table Definition of TblElemento *----------
    Set Tbl(8) = New ADOX.Table
    Tbl(8).ParentCatalog = Cat
    With Tbl(8)
        .Name = "TblElemento"
        .Columns.Append "IDElemento", adInteger
            .Columns("IDElemento").Properties("AutoIncrement").value = True
            .Columns("IDElemento").Properties("Nullable").value = True
            .Columns("IDElemento").Properties("Jet OLEDB:Compressed UNICODE Strings").value = False
            '.Columns("IDElemento").Properties(adPropRequired).value = IS_REQ
            .Columns("IDElemento").Properties("Default").value = vbNullString
        .Columns.Append "IDcd", adInteger
            .Columns("IDcd").Properties("Default").value = 0
            '.Columns("IDcd").Properties(adPropRequired).value = IS_REQ
            .Columns("IDcd").Properties("Jet OLEDB:Compressed UNICODE Strings").value = False
            .Columns("IDcd").Properties("Default").value = 0
            .Columns("IDcd").Properties("Nullable").value = False
        .Columns.Append "NomeFile", adVarWChar, 255
            '.Columns("NomeFile").Properties(adPropRequired).value = IS_REQ
            .Columns("NomeFile").Properties("Jet OLEDB:Allow Zero Length").value = True
            .Columns("NomeFile").Properties("Jet OLEDB:Compressed UNICODE Strings").value = True
            .Columns("NomeFile").Properties("Default").value = vbNullString
            .Columns("NomeFile").Properties("Nullable").value = False
        .Columns.Append "PercorsoFile", adVarWChar, 255
            '.Columns("PercorsoFile").Properties(adPropRequired).value = IS_REQ
            .Columns("PercorsoFile").Properties("Jet OLEDB:Allow Zero Length").value = True
            .Columns("PercorsoFile").Properties("Default").value = vbNullString
            .Columns("PercorsoFile").Properties("Nullable").value = False
        .Columns.Append "IDTipo", adInteger
            .Columns("IDTipo").Properties("Default").value = 0
            '.Columns("IDTipo").Properties(adPropRequired).value = IS_REQ
            .Columns("IDTipo").Properties("Jet OLEDB:Compressed UNICODE Strings").value = False
            .Columns("IDTipo").Properties("Default").value = 0
            .Columns("IDTipo").Properties("Nullable").value = False
        .Columns.Append "Descrizione", adLongVarWChar
            .Columns("Descrizione").Properties("Nullable").value = True
            '.Columns("Descrizione").Attributes = adColNullable '.Properties(adPropRequired).value = NOT_REQ
            .Columns("Descrizione").Properties("Jet OLEDB:Compressed UNICODE Strings").value = False
            .Columns("Descrizione").Properties("Jet OLEDB:Allow Zero Length").value = True
            .Columns("Descrizione").Properties("Default").value = vbNullString
    End With
    
    '----------* Index Definitions of TblElemento *----------
    ReDim Idx(6)
    Set Idx(0) = New ADOX.Index
        Idx(0).Name = "IDElemento"
        Idx(0).IndexNulls = adIndexNullsAllow
        Idx(0).Unique = True
        Idx(0).Columns.Append "IDElemento"
    Set Idx(1) = New ADOX.Index
        Idx(1).Name = "PrimaryKey"
        Idx(1).PrimaryKey = True
        Idx(1).Unique = True
        Idx(1).Columns.Append "IDcd"
        Idx(1).Columns.Append "NomeFile"
        Idx(1).Columns.Append "PercorsoFile"
    Set Idx(2) = New ADOX.Index
        Idx(2).Name = "Descrizione"
        Idx(2).IndexNulls = adIndexNullsAllow
        Idx(2).Columns.Append "Descrizione"
    Set Idx(3) = New ADOX.Index
        Idx(3).Name = "IDcd"
        Idx(3).IndexNulls = adIndexNullsAllow
        Idx(3).Columns.Append "IDcd"
    Set Idx(4) = New ADOX.Index
        Idx(4).Name = "IDTipo"
        Idx(4).IndexNulls = adIndexNullsAllow
        Idx(4).Columns.Append "IDTipo"
    Set Idx(5) = New ADOX.Index
        Idx(5).Name = "NomeFile"
        Idx(5).IndexNulls = adIndexNullsAllow
        Idx(5).Columns.Append "NomeFile"
    Set Idx(6) = New ADOX.Index
        Idx(6).Name = "PercorsoFile"
        Idx(6).IndexNulls = adIndexNullsAllow
        Idx(6).Columns.Append "PercorsoFile"
    'Set Idx(7) = New ADOX.Index
    '    Idx(7).Name = "TblCDTblElemento"
    '    Idx(7).IndexNulls = adIndexNullsAllow
    '    Idx(7).Properties("Foreign") = -1
    '    Idx(7).Columns.Append "IDcd"
    'Set Idx(8) = New ADOX.Index
    '    Idx(8).Name = "TblTipoTblElemento"
    '    Idx(8).IndexNulls = adIndexNullsAllow
    '    Idx(8).Properties("Foreign") = -1
    '    Idx(8).Columns.Append "IDTipo"
        
    For i = 0 To UBound(Idx)
        Tbl(8).Indexes.Append Idx(i)
    Next i

    Cat.Tables.Append Tbl(8)

    '----------* Table Definition of TblCD *----------
    Set Tbl(6) = New ADOX.Table
    Tbl(6).ParentCatalog = Cat
    With Tbl(6)
        .Name = "TblCD"
        .Columns.Append "IDcd", adInteger
        .Columns("IDcd").Properties("AutoIncrement").value = True
        .Columns("IDcd").Properties("Nullable").value = True
        .Columns("IDcd").Properties("Jet OLEDB:Compressed UNICODE Strings").value = False
        '.Columns("IDcd").Properties(adPropRequired).value = IS_REQ
        .Columns("IDcd").Properties("Default").value = vbNullString
        
        .Columns.Append "NomeCD", adVarWChar, 50
        .Columns("NomeCD").Properties("Nullable").value = False
        '.Columns("NomeCD").Properties(adPropRequired).value = IS_REQ
        .Columns("NomeCD").Properties("Jet OLEDB:Allow Zero Length").value = False
        .Columns("NomeCD").Properties("Default").value = vbNullString
        
        .Columns.Append "EtichettaCD", adVarWChar, 50
        .Columns("EtichettaCD").Properties("Nullable").value = True
        '.Columns("EtichettaCD").Attributes = adColNullable '.Properties(adPropRequired).value = IS_REQ
        .Columns("EtichettaCD").Properties("Jet OLEDB:Allow Zero Length").value = True
        .Columns("EtichettaCD").Properties("Default").value = vbNullString
    End With
  
    '----------* Index Definitions of TblCD *----------
    ReDim Idx(3)
    Set Idx(0) = New ADOX.Index
        Idx(0).Name = "NomeCD"
        Idx(0).IndexNulls = adIndexNullsAllow
        Idx(0).Unique = True
        Idx(0).Columns.Append "NomeCD"
    Set Idx(1) = New ADOX.Index
        Idx(1).Name = "PrimaryKey"
        Idx(1).PrimaryKey = True
        Idx(1).Unique = True
        Idx(1).Columns.Append "IDcd"
    Set Idx(2) = New ADOX.Index
        Idx(2).Name = "EtichettaCD"
        Idx(2).IndexNulls = adIndexNullsAllow
        Idx(2).Columns.Append "EtichettaCD"
    Set Idx(3) = New ADOX.Index
        Idx(3).Name = "IDcd"
        Idx(3).IndexNulls = adIndexNullsAllow
        Idx(3).Columns.Append "IDcd"
        
    For i = 0 To UBound(Idx)
        Tbl(6).Indexes.Append Idx(i)
    Next i
    
    Cat.Tables.Append Tbl(6)
    
    '----------* Table Definition of TblTipo *----------
    Set Tbl(9) = New ADOX.Table
    Tbl(9).ParentCatalog = Cat
    With Tbl(9)
        .Name = "TblTipo"
        .Columns.Append "IDTipo", adInteger
            .Columns("IDTipo").Properties("AutoIncrement").value = True
            '.Columns("IDTipo").Properties(adPropRequired).value = IS_REQ
            .Columns("IDTipo").Properties("Nullable").value = True
            .Columns("IDTipo").Properties("Jet OLEDB:Compressed UNICODE Strings").value = False
            .Columns("IDTipo").Properties("Default").value = vbNullString
        .Columns.Append "NomeTipo", adVarWChar, 50
            '.Columns("NomeTipo").Attributes = adColNullable '.Properties(adPropRequired).value = NOT_REQ
            .Columns("NomeTipo").Properties("Jet OLEDB:Allow Zero Length").value = False
            .Columns("NomeTipo").Properties("Default").value = vbNullString
            .Columns("NomeTipo").Properties("Nullable").value = False
        .Columns.Append "EstensioniAssociate", adLongVarWChar
            '.Columns("EstensioniAssociate").Attributes = adColNullable '.Properties(adPropRequired).value = IS_REQ
            .Columns("EstensioniAssociate").Properties("Nullable").value = True
            .Columns("EstensioniAssociate").Properties("Jet OLEDB:Allow Zero Length").value = True
            .Columns("EstensioniAssociate").Properties("Default").value = vbNullString
    End With
    '----------* Index Definitions of TblTipo *----------
    ReDim Idx(3)
    Set Idx(0) = New ADOX.Index
        Idx(0).Name = "NomeTipo"
        Idx(0).IndexNulls = adIndexNullsAllow
        Idx(0).Unique = True
        Idx(0).Columns.Append "NomeTipo"
    Set Idx(1) = New ADOX.Index
        Idx(1).Name = "PrimaryKey"
        Idx(1).PrimaryKey = True
        Idx(1).Unique = True
        Idx(1).Columns.Append "IDTipo"
    Set Idx(2) = New ADOX.Index
        Idx(2).Name = "EstensioniAssociate"
        Idx(2).IndexNulls = adIndexNullsAllow
        Idx(2).Columns.Append "EstensioniAssociate"
    Set Idx(3) = New ADOX.Index
        Idx(3).Name = "IDTipo"
        Idx(3).IndexNulls = adIndexNullsAllow
        Idx(3).Columns.Append "IDTipo"
        
    For i = 0 To UBound(Idx)
        Tbl(9).Indexes.Append Idx(i)
    Next i

    Cat.Tables.Append Tbl(9)
    
    '----------* Relation *----------
    Set kyForeign = New ADOX.Key
    'Definisce la chiave esterna
    kyForeign.Name = "TblCDTblElemento"
    kyForeign.Type = adKeyForeign
    kyForeign.RelatedTable = "TblCD"
    kyForeign.Columns.Append "IDcd"
    kyForeign.Columns("IDcd").RelatedColumn = "IDcd"
    kyForeign.UpdateRule = adRINone
    ' Aggiunge la chiave esterna
    Cat.Tables("TblElemento").Keys.Append kyForeign '"TblCDTblElemento", adKeyForeign, Cat.Tables("TblElemento").Columns("IDcd").Name, Cat.Tables("TblCD").Name, Cat.Tables("TblCD").Columns("IDcd").Name

    Set kyForeign = New ADOX.Key
    'Definisce la chiave esterna
    kyForeign.Name = "TblTipoTblElemento"
    kyForeign.Type = adKeyForeign
    kyForeign.RelatedTable = "TblTipo"
    kyForeign.Columns.Append "IDTipo"
    kyForeign.Columns("IDTipo").RelatedColumn = "IDTipo"
    kyForeign.UpdateRule = adRINone
    ' Aggiunge la chiave esterna
    Cat.Tables("TblElemento").Keys.Append kyForeign
    
    Set kyForeign = Nothing
    
    '----------* Queries *----------
    Set cmb = New ADODB.Command
    
    cmb.CommandText = "SELECT TblCD.IDcd, TblCD.NomeCD FROM TblCD;"
    Cat.Views.Append VIEWCD, cmb
    Set cmb = New ADODB.Command
    cmb.CommandText = "SELECT TblData.DataUltimoInserimento FROM TblData;"
    Cat.Views.Append VIEWDATA, cmb
    Set cmb = New ADODB.Command
    cmb.CommandText = "PARAMETERS Param Text ( 255 );SELECT TblElemento.IDElemento, TblElemento.NomeFile, TblElemento.PercorsoFile, TblTipo.NomeTipo, TblCD.NomeCD, TblElemento.Descrizione FROM TblTipo INNER JOIN (TblCD INNER JOIN TblElemento ON TblCD.IDcd = TblElemento.IDcd) ON TblTipo.IDTipo = TblElemento.IDTipo WHERE (((TblElemento.Descrizione) ALike ""%"" & [Param] & ""%"")) OR ((([TblElemento].[PercorsoFile]+[TblElemento].[NomeFile]) ALike ""%"" & [Param] & ""%""));"
    Cat.Views.Append VIEWELEMENTO, cmb
    Set cmb = New ADODB.Command
    cmb.CommandText = "PARAMETERS Param Text ( 255 );SELECT TblElemento.IDElemento, TblElemento.NomeFile, TblElemento.PercorsoFile, TblTipo.NomeTipo, TblCD.NomeCD, TblElemento.Descrizione FROM TblTipo INNER JOIN (TblCD INNER JOIN TblElemento ON TblCD.IDcd = TblElemento.IDcd) ON TblTipo.IDTipo = TblElemento.IDTipo WHERE (((TblCD.IDcd)=[param]));"
    Cat.Views.Append VIEWELEMENTOCD, cmb
    Set cmb = New ADODB.Command
    cmb.CommandText = "PARAMETERS Param Text ( 255 );SELECT TblElemento.IDElemento, TblElemento.NomeFile, TblElemento.PercorsoFile, TblTipo.NomeTipo, TblCD.NomeCD, TblElemento.Descrizione FROM TblTipo INNER JOIN (TblCD INNER JOIN TblElemento ON TblCD.IDcd = TblElemento.IDcd) ON TblTipo.IDTipo = TblElemento.IDTipo WHERE (((TblTipo.NomeTipo)=[ID]) AND ((TblElemento.Descrizione) ALike ""%"" & [Param] & ""%"")) OR (((TblTipo.NomeTipo)=[ID]) AND (([TblElemento].[PercorsoFile]+[TblElemento].[NomeFile]) ALike ""%"" & [Param] & ""%""));"
    Cat.Views.Append VIEWELEMENTOTIPO, cmb
    Set cmb = New ADODB.Command
    cmb.CommandText = "SELECT TblTipo.IDTipo, TblTipo.EstensioniAssociate, TblTipo.NomeTipo From TblTipo WHERE (((TblTipo.IDTipo)=[param]));"
    Cat.Views.Append VIEWESTENSIONI, cmb
    Set cmb = New ADODB.Command
    cmb.CommandText = "SELECT TblTipo.IDTipo, TblTipo.NomeTipo, TblTipo.EstensioniAssociate From TblTipo WHERE (((TblTipo.NomeTipo)=[param]));"
    Cat.Views.Append VIEWEXTNOMETIPO, cmb
    Set cmb = New ADODB.Command
    cmb.CommandText = "SELECT TblTipo.IDTipo, TblTipo.NomeTipo, TblTipo.EstensioniAssociate From TblTipo WHERE (((TblTipo.EstensioniAssociate) ALike ""%;"" & [param] & "";%""));"
    Cat.Views.Append VIEWGETEXT, cmb
    Set cmb = New ADODB.Command
    cmb.CommandText = "SELECT TblCD.IDcd, TblCD.NomeCD, TblCD.EtichettaCD From TblCD WHERE (((TblCD.NomeCD)=[param]));"
    Cat.Views.Append VIEWGETIDCD, cmb
    Set cmb = New ADODB.Command
    cmb.CommandText = "SELECT TblElemento.IDElemento From TblElemento WHERE (((TblElemento.IDcd)=[param1]) AND ((TblElemento.NomeFile)=[param2]) AND ((TblElemento.PercorsoFile)=[param3]));"
    Cat.Views.Append VIEWGETIDELEMENTO, cmb
    Set cmb = New ADODB.Command
    cmb.CommandText = "SELECT TblCD.IDcd, TblCD.NomeCD, TblCD.EtichettaCD From TblCD WHERE (((TblCD.EtichettaCD) ALike [param]));"
    Cat.Views.Append VIEWGETLABEL, cmb
    Set cmb = New ADODB.Command
    cmb.CommandText = "SELECT TblCD.IDcd, TblCD.NomeCD, TblCD.EtichettaCD From TblCD WHERE (((TblCD.IDcd)=[param]));"
    Cat.Views.Append VIEWLABEL, cmb
    Set cmb = New ADODB.Command
    cmb.CommandText = "SELECT TblElemento.IDcd, TblElemento.PercorsoFile From TblElemento Where (((TblElemento.IDcd)=[Param])) GROUP BY TblElemento.IDcd, TblElemento.PercorsoFile;"
    Cat.Views.Append VIEWPERCORSO, cmb
    Set cmb = New ADODB.Command
    cmb.CommandText = "SELECT TblElemento.IDElemento, TblElemento.NomeFile, TblElemento.PercorsoFile, TblTipo.NomeTipo, TblCD.NomeCD, TblElemento.Descrizione, TblCD.IDcd FROM TblTipo INNER JOIN (TblCD INNER JOIN TblElemento ON TblCD.IDcd = TblElemento.IDcd) ON TblTipo.IDTipo = TblElemento.IDTipo WHERE (((TblElemento.PercorsoFile)=[param1]) AND ((TblCD.IDcd)=[param2]));"
    Cat.Views.Append VIEWPERCORSOCD, cmb
    Set cmb = New ADODB.Command
    cmb.CommandText = "SELECT TblTipo.IDTipo, TblTipo.NomeTipo, TblTipo.EstensioniAssociate From TblTipo WHERE (((TblTipo.NomeTipo)<>""Directory""));"
    Cat.Views.Append VIEWTIPO, cmb
    Set cmb = New ADODB.Command
    
    cmb.CommandText = "PARAMETERS param1 Long, param2 Text; UPDATE TblElemento SET TblElemento.IDTipo = [param2] WHERE (LCase(Mid([NomeFile],InStrRev([NomeFile],"".""),Len([NomeFile])-InStrRev([NomeFile],""."")+1)))=[param1];"
    Cat.Views.Append SPASSOCIAZIONI, cmb
    Set cmb = New ADODB.Command
    cmb.CommandText = "DELETE TblCD.IDCD From TblCD WHERE (((TblCD.IDcd)=[param]));"
    Cat.Views.Append SPDELCD, cmb
    Set cmb = New ADODB.Command
    cmb.CommandText = "DELETE TblData.DataUltimoInserimento FROM TblData;"
    Cat.Views.Append SPDELDATA, cmb
    Set cmb = New ADODB.Command
    cmb.CommandText = "PARAMETERS id Long;Delete TblElemento.IDElemento From TblElemento WHERE (((TblElemento.IDElemento)=[id]));"
    Cat.Views.Append SPDELELEMENTO, cmb
    Set cmb = New ADODB.Command
    cmb.CommandText = "DELETE TblElemento.IDElemento From TblElemento WHERE (((TblElemento.PercorsoFile) Like [Param] & ""%"") And ((TblElemento.IDcd)=[param2]));"
    Cat.Views.Append SPDELFOLDER, cmb
    Set cmb = New ADODB.Command
    cmb.CommandText = "DELETE TblTipo.IDTipo From TblTipo WHERE (((TblTipo.IDTipo)=[param]));"
    Cat.Views.Append SPDELTIPO, cmb
    Set cmb = New ADODB.Command
    cmb.CommandText = "PARAMETERS param1 Long, param2 Text;UPDATE TblTipo SET TblTipo.EstensioniAssociate = [param2] WHERE (((TblTipo.IDTipo)=[param1]));"
    Cat.Views.Append SPESTENSIONI, cmb
    Set cmb = New ADODB.Command
    cmb.CommandText = "PARAMETERS param1 Long, param2 Text;UPDATE TblCD SET TblCD.EtichettaCD = [param2] WHERE (((TblCD.IDCD)=[param1]));"
    Cat.Views.Append SPETICHETTE, cmb
    Set cmb = New ADODB.Command
    cmb.CommandText = "INSERT INTO tblElemento ( NomeFile, PercorsoFile, IDTipo, IDcd, Descrizione ) VALUES (Nome, Percorso, Tipo, CD, Descr);"
    Cat.Views.Append SPINS, cmb
    Set cmb = New ADODB.Command
    cmb.CommandText = "INSERT INTO TblCD ( NomeCD ) VALUES (Nome);"
    Cat.Views.Append SPINSCD, cmb
    Set cmb = New ADODB.Command
    cmb.CommandText = "INSERT INTO TblCD ( NomeCD, EtichettaCD )VALUES (Nome, Etichetta);"
    Cat.Views.Append SPINSCDLABEL, cmb
    Set cmb = New ADODB.Command
    cmb.CommandText = "INSERT INTO TblData ( DataUltimoInserimento ) SELECT Date() AS Espr1;"
    Cat.Views.Append SPINSDATA, cmb
    Set cmb = New ADODB.Command
    cmb.CommandText = "INSERT INTO TblTipo ( NomeTipo )VALUES (Nome);"
    Cat.Views.Append SPINSTIPO, cmb
    Set cmb = New ADODB.Command
    cmb.CommandText = "PARAMETERS id Long, param1 Text ( 255 );UPDATE TblElemento SET TblElemento.Descrizione = [param1] WHERE (((TblElemento.IDElemento)=[ID]));"
    Cat.Views.Append SPUPDATEELEMENTO, cmb
    Set cmb = New ADODB.Command
    cmb.CommandText = "PARAMETERS OldID Long, Ext Text, NewID Long;UPDATE TblElemento SET TblElemento.IDTipo = [NewID] WHERE (((TblElemento.IDTipo)=[OldID]) AND ((TblElemento.NomeFile) ALike ""%"" & [ext]));"
    Cat.Views.Append SPUPDATETIPO, cmb
    Set cmb = New ADODB.Command
    cmb.CommandText = "PARAMETERS NewNomeCD Text, OldNomeCD Text; UPDATE TblCD SET TblCD.NomeCD = [NewNomeCD] WHERE TblCD.NomeCD=[OldNomeCD];"
    Cat.Views.Append SPUPDATECD, cmb

    
    '----------* Dati iniziali *----------
    Set rst = New ADODB.Recordset
    Set cnn = New ADODB.Connection
    cnn.Open sCnn
    rst.Open "TblTipo", cnn, adOpenForwardOnly, adLockOptimistic, adCmdTable
    rst.AddNew
    rst!NomeTipo = "Directory"
    rst!EstensioniAssociate = vbNullString
    rst.Update
    
    rst.AddNew
    rst!NomeTipo = "Programma"
    rst!EstensioniAssociate = ";exe;com;dll;"
    rst.Update
    
    rst.AddNew
    rst!NomeTipo = "Archivio"
    rst!EstensioniAssociate = ";zip;rar;ace;gz;tar;arj;cab;jar;lha;lzh;z;tgz;"
    rst.Update
    
    rst.AddNew
    rst!NomeTipo = "Documento"
    rst!EstensioniAssociate = ";doc;txt;pdf;htm;html;asc;mdb;nfo;xls;hlp;"
    rst.Update
    
    rst.AddNew
    rst!NomeTipo = "Multimediale"
    rst!EstensioniAssociate = ";mp3;avi;mpeg;mpg;asf;mpe;mov;rm;mid;pff;wav;cda;"
    rst.Update
    
    rst.AddNew
    rst!NomeTipo = "Codice Sorgente"
    rst!EstensioniAssociate = ";asm;asp;c;cgi;cls;class;cpp;frm;vbp;h;hpp;inc;js;java;"
    rst.Update
    
    rst.AddNew
    rst!NomeTipo = "Immagini"
    rst!EstensioniAssociate = ";bmp;gif;jpg;jpeg;tiff;jff;jif;jtf;ico;"
    rst.Update
    
    rst.AddNew
    rst!NomeTipo = "Eseguibili Linux"
    rst!EstensioniAssociate = ";bin;rpm;deb;"
    rst.Update
    
    rst.AddNew
    rst!NomeTipo = "Informazioni Aggiuntive"
    rst!EstensioniAssociate = ";dat;"
    rst.Update
    
    rst.AddNew
    rst!NomeTipo = "Cestino"
    rst!EstensioniAssociate = ";diz;psh;ppm;"
    rst.Update
    
    rst.AddNew
    rst!NomeTipo = "Fonts"
    rst!EstensioniAssociate = ";ttf;"
    rst.Update
    
    Set cmb = Nothing
    Erase Idx()
    Erase Tbl()
    Set Cat = Nothing
    CreateDatabase = True
    Exit Function

ErrorCreateDB:
    err.Source = "ModDB.CreateDatabase"
    Call ModErrori.GestisciErrore
    Set cmb = Nothing
    Erase Idx()
    Erase Tbl()
    Set kyForeign = Nothing
    Set Cat = Nothing
End Function

